package com.rchat.pocmini.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.rchat.pocmini.R;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	
	private static final String TAG = "WXPayEntryActivity";
	
    private IWXAPI api;
	private TextView tvPayResult;
	private TextView tvShowMoney;
	private Button btnFinish;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result_layout);

		tvPayResult = (TextView)findViewById(R.id.tv_pay_result);
		tvShowMoney = (TextView)findViewById(R.id.tv_show_money) ;
		btnFinish = (Button)findViewById(R.id.btn_finish);
		btnFinish.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				finish();
			}
		});

		api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {

//		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setTitle(R.string.app_tip);
//			builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
//			builder.show();
//		}

		switch (resp.errCode){
			case 0:
				tvPayResult.setText(R.string.pay_success);
				tvShowMoney.setText("¥" + resp.transaction);
				break;
			case -1:
				tvPayResult.setText(R.string.pay_fail);
				tvShowMoney.setText("¥" + resp.transaction);
				break;
			case -2:
				tvPayResult.setText(R.string.pay_cancel);
				tvShowMoney.setText("¥" + resp.transaction);
				break;
		}
	}
}